function loading() {
	//$("#loading-container").empty();
	//$("#loading-container").append('<div id="loading" class="loading-invisible"><img src="/swf-qudex-collections/css/ajax-loader.gif" /></div>');
	//ORIGINAL LINE document.getElementById("loading").className = "loading-visible";
	//$("#loading").show();
	//WORKS IN EXPLORER
	 //var pb = document.getElementById("loading");
	 //if (pb != null) {
		// pb.innerHTML = '<img src="/swf-qudex-spreadsheet/css/ajax-loader.gif" />';
		 //pb.className = "loading-visible";
		 $.blockUI({ message: '<img src="/swf-qudex-spreadsheet/css/ajax-loader.gif" />' });
	 //}
}
function deleteZipFile(index) {
	var hiddenElem = document.getElementById("removeIndex");
	if (hiddenElem != null)
		hiddenElem.Value = index;
}

function customEncode(url) {
	return escape(url);
}
function setAction(formId, action) { 

	var form = document.getElementById(formId);
	form.methodToCall.value = action; 
	form.submit(); 
}

function setRname(formId, name) { 

	var form = document.getElementById(formId);
	
	form.rName.value = name; 
}

function eliminateElements(formId) {
	var form = document.getElementById(formId);

	var checkBoxList = form.getElementsByTagName("input");
	
	var idsList = "";
	
	for(var i=0; i < checkBoxList.length; i++) {
		if (checkBoxList[i].type =="checkbox" && checkBoxList[i].checked == true) {
			idsList += checkBoxList[i].name;
			if (i < checkBoxList.length - 1)
				idsList += ';';
		}
	}

	form.elimList.value = idsList;
}

function SetAllCheckBoxes(FormName, CheckValue) {
	if (!document.forms[FormName])
		return;
	var objCheckBoxes = document.forms[FormName].getElementsByTagName("input");
	if (!objCheckBoxes)
		return;
	var countCheckBoxes = objCheckBoxes.length;
	if (!countCheckBoxes)
		objCheckBoxes.checked = CheckValue;
	else {
		// set the check value for all check boxes
		//<![CDATA[
		for ( var i = 0; i < countCheckBoxes; i++)
			//]]>
			if (objCheckBoxes[i].type =="checkbox" && !objCheckBoxes[i].disabled)
				objCheckBoxes[i].checked = CheckValue;
	}
}
function enableElements(formId) {
	var objCheckBoxes = document.forms[formId].getElementsByTagName("input");
	if (!objCheckBoxes)
		return;
	var countCheckBoxes = objCheckBoxes.length;
	if (!countCheckBoxes)
		objCheckBoxes.checked = CheckValue;
	else {
		// set the check value for all check boxes
		//<![CDATA[
		for ( var i = 0; i < countCheckBoxes; i++)
			//]]>
			if (objCheckBoxes[i].type =="checkbox")
				objCheckBoxes[i].disabled = false;
	}
}
function createList(formName, field) {
	if (!document.forms[formName])
		return;

	var objCheckBoxes = document.forms[formName].elements[field];

	if (!objCheckBoxes)
		return;

	var countCheckBoxes = objCheckBoxes.length;

	if (!countCheckBoxes) {
		return;
	} else {
		var list = "";
		//<![CDATA[
		for ( var i = 0; i < countCheckBoxes; i++)
			//]]>
		{
			if (objCheckBoxes[i].checked == true) {
				list += objCheckBoxes[i].id + ';';
			}
		}
		if (list[list.length - 1] == ';')
			list[list.length - 1] = '';
		//alert(list);
		document.forms[formName].elements["listMetadataElements"].setAttribute(
				"value", list);
	}
}
function eliminateSchema(formName, index, option) {
	var form = document.getElementById(formName);

	form.index.value = index;
	if (option == 1)
		form.methodToCall.value = 'deleteDatastream';
	else form.methodToCall.value = 'deleteMetadata';
	form.submit();
}
function verify() {
	var answer = confirm("Are you sure you want to generate the spreadsheet with the current settings?");
	if (answer) {
		return true;

	} else {
		return false;
	}
}
//POP-UP Management
var newwindow = '';

function popitup(url) {
	if (newwindow.location && !newwindow.closed) {
	    newwindow.location.href = url;
	    newwindow.focus(); }
	else {
		//SIZE HARDCODED TO IMAGES SIZE
	    newwindow=window.open(url,'htmlname','width=900,height=391,resizable=1');
	    }
}

function tidy() {
	if (newwindow.location && !newwindow.closed) {
	   newwindow.close(); 
	}
}
